/*
 * iShopPlace Project.
 */
package ishopplace.view.bean;

import ishopplace.model.businessobject.*;
import ishopplace.model.exception.iShopPlaceException;

import javax.faces.FacesException;


/**
 * Item page backing bean for the view item page.
 * 
 * @author <a href="mailto:derek@derekshen.com">Derek Y. Shen</a>
 */
public class ItemPageBean extends BaseBean {
	private String itemId;
	private Item item;
	
	public ItemPageBean() {
		super();
		this.logger.debug("ItemPageBean is created");
	}
	
	/**
	 * Initializes ItemPageBean.
	 * 
	 * @see BaseBean#init()
	 */
	protected void init() {
		this.logger.debug("init() is invoked");
		this.logger.debug("itemId = " + this.itemId);
		if (this.itemId != null) {
			try {
				this.item = this.getServiceLocator().getCatalogService().getItem(itemId);
			} catch (iShopPlaceException me) {
				String msg = "Could not retrieve item with id of " + this.itemId;
				this.logger.error(msg, me);
				throw new FacesException(msg, me);
			}
		}
		this.logger.debug("ItemPageBean is initialized");
	}
	
	public void setItemId(String newItemId) {
		this.itemId = newItemId;
	}
	
	public Item getItem() {
		return this.item;
	}
}
